package tools;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

public class Logger {
    public static String loggerpath = SQLConstant.getRootpath()+"/log";
    public static String date;

    public static void log(String str) throws IOException {
        String date = LocalDate.now().toString();
        File logfile = new File(loggerpath+"/"+date+".txt");
        if(!logfile.exists())
        {
            logfile.createNewFile();
        }
        try (PrintWriter writer = new PrintWriter(new FileWriter(logfile,true))) {
            writer.println(LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss")) +':'+ str);
        } catch (IOException e) {
            System.out.println("Error writing to file: " + e.getMessage());
        }
    }
}
